home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / DirTreeView.cpp < prev    next >
C/C++ Source or Header  |  2001-10-28  |  20KB  |  745 lines

  1. // DirTreeView.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "winhttrack.h"
  6. #include "DirTreeView.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. #include "MainFrm.h"
  15.  
  16. CDirTreeView* this_DirTreeView=NULL;
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CDirTreeView
  20.  
  21. IMPLEMENT_DYNCREATE(CDirTreeView, CTreeView)
  22.  
  23. CDirTreeView::CDirTreeView()
  24. {
  25.   this_DirTreeView=this;
  26.   redraw_in_progress=0;
  27.   timer=0;
  28.   count_whandle=0;
  29.   docType="<nullType>";
  30. }
  31.  
  32. CDirTreeView::~CDirTreeView()
  33. {
  34.   WaitThreads();
  35.   this_DirTreeView=NULL;
  36.   if (imagelist.m_hImageList) {
  37.     imagelist.Detach();
  38.     imagelist.m_hImageList=NULL;
  39.   }
  40. }
  41.  
  42.  
  43. BEGIN_MESSAGE_MAP(CDirTreeView, CTreeView)
  44.     //{{AFX_MSG_MAP(CDirTreeView)
  45.     ON_WM_TIMER()
  46.     ON_WM_SHOWWINDOW()
  47.     ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
  48.     ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
  49.     ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
  50.     ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit)
  51.     ON_NOTIFY_REFLECT(TVN_KEYDOWN, OnKeydown)
  52.     ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
  53.     ON_WM_KILLFOCUS()
  54.     ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  55.     //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CDirTreeView drawing
  60.  
  61. void CDirTreeView::OnDraw(CDC* pDC)
  62. {
  63.     CDocument* pDoc = GetDocument();
  64.     // TODO: add draw code here
  65. }
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CDirTreeView diagnostics
  69.  
  70. #ifdef _DEBUG
  71. void CDirTreeView::AssertValid() const
  72. {
  73.     CTreeView::AssertValid();
  74. }
  75.  
  76. void CDirTreeView::Dump(CDumpContext& dc) const
  77. {
  78.     CTreeView::Dump(dc);
  79. }
  80. #endif //_DEBUG
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CDirTreeView message handlers
  84.  
  85.  
  86. BOOL CDirTreeView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  87. {
  88.   dwStyle|=(TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS|TVS_EDITLABELS);
  89.   //dwStyle|=(TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS|TVS_DISABLEDRAGDROP);
  90.   //
  91.   dwStyle&=(~(TVS_NOTOOLTIPS));     /* disabled */
  92.  
  93. /*
  94.   dwStyle|=(WS_DISABLED);
  95.   dwStyle&=(~(WS_VISIBLE));
  96. */
  97.  
  98.   int r=CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  99.  
  100.   GetTreeCtrl().SetImageList(&imagelist,TVSIL_NORMAL);
  101.   /*GetTreeCtrl().SetToolTips(&m_TreeViewToolTip);*/
  102.  
  103.   RefreshTree();
  104.   return r;
  105. }
  106.  
  107.  
  108. void CDirTreeView::RefreshTree() {
  109.   CTreeCtrl& tree=GetTreeCtrl();
  110.   if (!tree) return;   /* error */
  111.  
  112.   tree.DeleteAllItems();
  113.   int len=32768;
  114.   char* adr=(char*)malloc(len+4);
  115.   if (adr) {
  116.     if (GetLogicalDriveStrings(len,adr)>0) {
  117.       char*a=adr;
  118.       while(*a) {
  119.         char* next=a+strlen(a)+1;
  120.         if (*(a+strlen(a)-1)=='\\')
  121.           *(a+strlen(a)-1)='\0';
  122.         HTREEITEM it=tree.InsertItem(a);
  123.         if (it) {
  124.           tree.SetItemText(it,"");
  125.           tree.InsertItem("expanding..",it,TVI_SORT);
  126.          
  127.           // icone
  128.           char name[256];
  129.           strcpy(name,a);
  130.           strcat(name,"\\");
  131.           SHFILEINFO info;
  132.           if (SHGetFileInfo(name,0,&info,sizeof(info),SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_SHELLICONSIZE | SHGFI_DISPLAYNAME)) {
  133.             //SHGetFileInfo(name,0,&info,sizeof(info),SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_TYPENAME | SHGFI_SHELLICONSIZE | SHGFI_DISPLAYNAME | SHGFI_ATTRIBUTES); 
  134.             tree.SetItemImage(it,info.iIcon,info.iIcon);
  135.             CString disp=info.szDisplayName;
  136.             if (disp.ReverseFind('('))
  137.               disp=disp.Left(disp.Find('('));
  138.             disp+="<"; disp+=a; disp+=">"; 
  139.             tree.SetItemText(it,disp);
  140.           }
  141.         }
  142.  
  143.         a=next;
  144.       }
  145.     }
  146.     free(adr);
  147.   }
  148.   
  149.   BuildTrackHandles();
  150. }
  151.  
  152. /* remise α zΘro */
  153. void CDirTreeView::ResetTree() {
  154.   if (!GetTreeCtrl()) return;   /* error */
  155.   RefreshTree();
  156.   StartTimer();
  157. }
  158.  
  159. /* attendre fin des threads refresh */
  160. void CDirTreeView::WaitThreads() {
  161.   /* attendre */
  162.   int w=0;
  163.   while((redraw_in_progress) && (w<10)) {
  164.     Sleep(100);
  165.     w++;
  166.   }
  167. }
  168.  
  169.  
  170. void CDirTreeView::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) 
  171. {
  172.   *pResult = 0;
  173.   if (GetTreeCtrl().GetStyle() & WS_VISIBLE) {    /* sinon pas de refresh */
  174.     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  175.     
  176.     // find out what item is getting expanded, and send that to Expand(hItem, TVE_EXPAND)
  177.     if (pNMTreeView->hdr.code == TVN_ITEMEXPANDING)
  178.     {
  179.       HTREEITEM hIT = pNMTreeView->itemNew.hItem;
  180.       DestroyTrackHandles();
  181.       if (!RefreshDir(hIT))
  182.         *pResult = 1;
  183.       BuildTrackHandles();
  184.     }
  185.   }
  186. }
  187.  
  188. void CDirTreeView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  189. {
  190.   NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  191.   // find out what item is getting expanded, and send that to Expand(hItem, TVE_EXPAND)
  192.   if (pNMTreeView->hdr.code == TVN_SELCHANGED)
  193.   {
  194.     HTREEITEM hIT = pNMTreeView->itemNew.hItem;
  195.     CString st=GetItemPath(hIT);
  196.   
  197.     CWnd* top_window=this;
  198.     while(top_window->GetParent())
  199.       top_window=top_window->GetParent();
  200.     ((CMainFrame*)top_window)->m_wndStatusBar.SetWindowText(st);
  201.   }    
  202.   *pResult = 0;
  203. }
  204.  
  205.  
  206. void CDirTreeView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
  207. {
  208.   HTREEITEM selected=GetTreeCtrl().GetSelectedItem();
  209.   if (selected) {
  210.     if (!GetTreeCtrl().ItemHasChildren(selected)) {
  211.       CString name=GetItemPath(selected);
  212.       if (name.Right(1)=="\\")
  213.         name=name.Left(name.GetLength()-1);
  214.       DWORD attrb=GetFileAttributes(name);
  215.       if (attrb!=0xFFFFFFFF) {
  216.         if ( !(attrb & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_TEMPORARY)) ) {
  217.           CWaitCursor wait;
  218.           if (docType.CompareNoCase(name.Right(docType.GetLength()))==0) {
  219.             CWinApp* app=AfxGetApp();
  220.             POSITION pos;
  221.             pos=app->GetFirstDocTemplatePosition();
  222.             CDocTemplate* templ = app->GetNextDocTemplate(pos);
  223.             pos=templ->GetFirstDocPosition();
  224.             CDocument* doc  = templ->GetNextDoc(pos);
  225.             if (doc) {
  226.               //if (doc->SaveModified()) {
  227.               AfxGetApp()->OpenDocumentFile(name);
  228.               //}
  229.             }
  230.           } else {
  231.             /* Lancer ShellEx en arriΦre plan */
  232.             AfxBeginThread(CDirTreeViewShellEx,new CString(name));
  233.           }
  234.         }
  235.       }
  236.     }
  237.   }
  238.   *pResult = 0;
  239. }
  240.  
  241. void CDirTreeView::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
  242. {
  243.   CTreeCtrl& tree=GetTreeCtrl();
  244.   if (!tree) return;
  245.  
  246.   HTREEITEM curr_selected=tree.GetDropHilightItem();
  247.   if (!curr_selected)
  248.     curr_selected=tree.GetSelectedItem();
  249.   if (curr_selected) {
  250.     /*
  251.     CString st=GetItemPath(curr_selected);
  252.   
  253.     CWnd* top_window=this;
  254.     while(top_window->GetParent())
  255.       top_window=top_window->GetParent();
  256.     ((CMainFrame*)top_window)->m_wndStatusBar.SetWindowText(st);
  257.     */
  258.   }
  259.  
  260.     *pResult = 0;
  261. }
  262.  
  263. void CDirTreeView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
  264. {
  265.   CTreeCtrl& tree=GetTreeCtrl();
  266.   if (!tree) return;
  267.   HTREEITEM curr_selected=tree.GetDropHilightItem();
  268.   if (!curr_selected)
  269.     curr_selected=tree.GetSelectedItem();
  270.   if (curr_selected) {
  271.     CString st=GetItemPath(curr_selected);
  272.     AfxMessageBox(st);
  273.   }
  274.   *pResult = 0;
  275. }
  276.  
  277.  
  278.  
  279. CString CDirTreeView::GetItemName(HTREEITEM position) {
  280.   CString st=GetTreeCtrl().GetItemText(position);
  281.   if (st.Find('<')) {
  282.     if (st.Right(2)==":>") {
  283.       st=st.Mid(st.Find('<')+1);
  284.       st=st.Left(st.GetLength()-1);
  285.     }
  286.   }
  287.   return st;
  288. }
  289.  
  290. CString CDirTreeView::GetItemPath(HTREEITEM position) {
  291.   if (position) {
  292.     HTREEITEM parent_it=GetTreeCtrl().GetParentItem(position);
  293.     CString st=GetItemName(position);
  294.     CString slash="";
  295.     if (GetTreeCtrl().ItemHasChildren(position))
  296.       slash="\\";
  297.     if (st.GetLength())
  298.       return GetItemPath(parent_it)+st+slash;
  299.     else
  300.       return GetItemPath(parent_it);
  301.   } else
  302.     return "";
  303. }
  304.  
  305. HTREEITEM CDirTreeView::GetPathItem(CString path,BOOL open,BOOL nofail,BOOL nohide,HTREEITEM rootposition) {
  306.   CTreeCtrl& tree=GetTreeCtrl();
  307.   if (!tree) return NULL;   /* error */
  308.   //
  309.   HTREEITEM return_value=NULL;
  310.   //
  311.   CString left="",right="";
  312.   int pos=path.Find('\\');
  313.   if (pos<0)
  314.     left=path;
  315.   else {
  316.     left=path.Left(pos);
  317.     right=path.Mid(pos+1);
  318.   }
  319.  
  320.   if (!nohide)
  321.     tree.ModifyStyle(WS_VISIBLE,0);
  322.   
  323.   HTREEITEM position;
  324.   if (!rootposition) {
  325.     rootposition=tree.GetRootItem();
  326.     /* position initiale */
  327.     position=rootposition;
  328.   } else {
  329.     // Ouvrir?
  330.     if (open) {
  331.       if (tree.ItemHasChildren(rootposition)) {        /* si enfants */
  332.         if (!(tree.GetItemState(rootposition,TVIF_STATE) & TVIS_EXPANDED)) {    /* si non ouvert */
  333.           /*tree.SetItemState(rootposition,TVIF_STATE,
  334.             tree.GetItemState(rootposition,TVIF_STATE) | TVIS_EXPANDED);
  335.             */
  336.           tree.Expand(rootposition,TVE_EXPAND);
  337.           RefreshDir(rootposition,TRUE);
  338.         }
  339.       }
  340.       
  341.     }
  342.  
  343.     /* position initiale */
  344.     position=tree.GetChildItem(rootposition);
  345.   }
  346.  
  347.   left.MakeLower();
  348.   while(position) {
  349.     CString st=GetItemName(position);
  350.     st.MakeLower();
  351.     if (st==left) {
  352.       if (right.GetLength())
  353.         position=GetPathItem(right,open,nofail,TRUE,position);
  354.       else
  355.         return_value=position;      // trouvΘ
  356.       position=NULL;
  357.     }
  358.     if (position)
  359.       position=tree.GetNextSiblingItem(position);
  360.   }
  361.  
  362.   // liste visible
  363.   if (!nohide) {
  364.     tree.ModifyStyle(0,WS_VISIBLE);
  365.     //RedrawWindow();
  366.     tree.GetParent()->RedrawWindow();
  367.   }
  368.   if (return_value)
  369.     return return_value;
  370.   else if (nofail)
  371.     return rootposition;
  372.   else
  373.     return NULL;
  374. }
  375.  
  376. BOOL CDirTreeView::EnsureVisible(CString path) {
  377.   if (!GetTreeCtrl()) return FALSE;   /* error */
  378. #if 0
  379.   /* Lancer refresh en arriΦre plan */
  380.   refreshPath=path;
  381.   StopTimer();
  382.   AfxBeginThread(CDirTreeViewRefresh,this);
  383.   return TRUE;
  384. #else
  385.   CWaitCursor wait;
  386.   HTREEITEM pos=GetPathItem(path,TRUE,TRUE);
  387.   if (pos) {
  388.     GetTreeCtrl().EnsureVisible(pos);
  389.   } else
  390.     return FALSE;
  391.   return TRUE;
  392. #endif
  393. }
  394.  
  395. BOOL CDirTreeView::EnsureVisibleBl(CString path) {
  396.   if (!GetTreeCtrl()) return FALSE;   /* error */
  397.   CWaitCursor wait;
  398.   int return_value=TRUE;
  399.   StopTimer();
  400.   HTREEITEM pos=GetPathItem(path,TRUE,TRUE);
  401.   if (pos) {
  402.     GetTreeCtrl().EnsureVisible(pos);
  403.   } else
  404.     return_value=FALSE;
  405.   StartTimer();
  406.   return return_value;
  407. }
  408.  
  409. void CDirTreeView::RefreshPos(HTREEITEM position) {
  410.   RefreshDir(position);
  411. }
  412.  
  413. BOOL CDirTreeView::RefreshDir(HTREEITEM position,BOOL nohide) {
  414.   CTreeCtrl& tree=GetTreeCtrl();
  415.   if (!tree) return FALSE;   /* error */
  416.  
  417.   CWaitCursor wait;
  418.   CString path=GetItemPath(position);
  419.   CString backup_visibles="\n";
  420.  
  421.   // Pour FindFirstFile/FindNextFile
  422.   WIN32_FIND_DATA find;
  423.   int type;
  424.   HANDLE h = FindFirstFile(path+"*.*",&find);
  425.  
  426.   // accessible
  427.   if (h!=INVALID_HANDLE_VALUE) {
  428.     // liste invisible
  429.     if (!nohide)
  430.       tree.ModifyStyle(WS_VISIBLE,0);
  431.  
  432.     { // backuper ΘlΘments visibles
  433.       HTREEITEM it=tree.GetChildItem(position);
  434.       int backup_visibles_count=0;
  435.       while(it) {
  436.         if (tree.ItemHasChildren(it)) {        /* si enfants */
  437.           if (tree.GetItemState(it,TVIF_STATE) & TVIS_EXPANDED) {    /* si ouvert */
  438.             backup_visibles+=(GetItemPath(it)+"\n");
  439.             backup_visibles_count++;
  440.           }
  441.         }
  442.         it=tree.GetNextVisibleItem(it);
  443.       }
  444.       if (!backup_visibles_count)
  445.         backup_visibles="";
  446.     }
  447.  
  448.     {  // effacer la liste
  449.       HTREEITEM it;
  450.       while(it=tree.GetChildItem(position))
  451.         tree.DeleteItem(it);
  452.     }
  453.     
  454.     // chargement de la liste
  455.     HTREEITEM last_dir_it=tree.GetRootItem();
  456.     for(type=0;type<2;type++) {
  457.       if (h != INVALID_HANDLE_VALUE) {
  458.         do {
  459.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN))) {
  460.             if (strcmp(find.cFileName,"..")) {
  461.               if (strcmp(find.cFileName,".")) {
  462.                 HTREEITEM it=NULL;
  463.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  464.                   if (type==0) {
  465.                     if (IsWindow(tree.m_hWnd)) {
  466.                       it=tree.InsertItem(find.cFileName,position);
  467.                       tree.InsertItem("expanding..",it,TVI_SORT);
  468.                     }
  469.                   }
  470.                 } else {
  471.                   if (type==1) {
  472.                     if (IsWindow(tree.m_hWnd))
  473.                       it=tree.InsertItem(find.cFileName,position,last_dir_it);
  474.                   }
  475.                 }
  476.                 // changer icone
  477.                 if (it) {
  478.                   SHFILEINFO info;
  479.                   SHGetFileInfo(path+find.cFileName,0,&info,sizeof(info),SHGFI_SYSICONINDEX);
  480.                   //SHGetFileInfo(path+find.cFileName,0,&info,sizeof(info),SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_TYPENAME | SHGFI_SHELLICONSIZE | SHGFI_DISPLAYNAME | SHGFI_ATTRIBUTES); 
  481.                   if (IsWindow(tree.GetSafeHwnd()))
  482.                     tree.SetItemImage(it,info.iIcon,info.iIcon);
  483.                 }
  484.               }
  485.             }
  486.           }
  487.         } while(FindNextFile(h,&find));
  488.         FindClose(h);
  489.       }
  490.       if (type==0)
  491.         h = FindFirstFile(path+"*.*",&find);
  492.     }
  493.  
  494.     // restaurer ΘlΘments visibles
  495.     RestoreVisibles(position,backup_visibles);
  496.  
  497.     // liste visible
  498.     if (!nohide)
  499.       tree.ModifyStyle(0,WS_VISIBLE);
  500.   }/* **OLD 
  501.   else
  502.     tree.Expand(position,TVE_COLLAPSE);
  503.    */
  504.  
  505.   // Redessiner
  506.   if (!nohide)
  507.     GetParent()->RedrawWindow();
  508.   return (h!=INVALID_HANDLE_VALUE);
  509. }
  510.  
  511. void CDirTreeView::RestoreVisibles(HTREEITEM position,CString& backup_visibles) {
  512.   CTreeCtrl& tree=GetTreeCtrl();
  513.   if (!tree) return;   /* error */
  514.  
  515.   if (backup_visibles.GetLength()) {
  516.     // rΘouvrir les ΘlΘments visibles
  517.     HTREEITEM it=tree.GetChildItem(position);
  518.     while(it) {
  519.       if (backup_visibles.Find("\n"+GetItemPath(it)+"\n")>=0) {
  520.         tree.Expand(it,TVE_EXPAND);
  521.         RefreshDir(it,TRUE);       /* car appelΘ par RefreshDir lui mΩme */
  522.         RestoreVisibles(it,backup_visibles);
  523.       }
  524.       it=tree.GetNextSiblingItem(it);
  525.     }
  526.   }
  527. }
  528.  
  529.  
  530.  
  531. void CDirTreeView::StartTimer() {
  532.   if (!timer) {
  533.     //whandle=FindFirstChangeNotification("C:\\",TRUE,FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME);
  534.     BuildTrackHandles();
  535.     timer=SetTimer(WM_TIMER,1000,NULL);
  536.   }
  537. }
  538. void CDirTreeView::StopTimer() {
  539.   if (timer) {
  540.     DestroyTrackHandles();
  541.     KillTimer(timer);
  542.     timer=0;
  543.   }
  544. }
  545.  
  546. void CDirTreeView::DestroyTrackHandles() 
  547. {
  548.   /* Fermer handles actuels */
  549.   if (count_whandle) {
  550.     int i;
  551.     for(i=0;i<count_whandle;i++)
  552.       FindCloseChangeNotification(whandle[i]);
  553.     count_whandle=0;
  554.   }
  555. }
  556.  
  557. void CDirTreeView::BuildTrackHandles() 
  558. {
  559.   if (!GetTreeCtrl()) return;   /* error */
  560.   DestroyTrackHandles();
  561.   /* Lecture ΘlΘments du root visibles (non, c'est pas rΘcursif vu que ce sont les Θlts visibles) */
  562.   CTreeCtrl& it=GetTreeCtrl();
  563.   HTREEITEM pos=it.GetFirstVisibleItem();
  564.   while(pos) {
  565.     CString path=GetItemPath(pos);
  566.     CFileStatus status;
  567.     if (it.ItemHasChildren(pos)) {        /* surveiller si enfants */
  568.       if (it.GetItemState(pos,TVIF_STATE) & TVIS_EXPANDED) {    /* si ouvert */
  569.         if (CFile::GetStatus(path.Left(path.GetLength()-1),status)) {   // rΘpertoire (note: path sans le / final)
  570.           if (status.m_attribute & 0x10 ) {       /* directory = 0x10 */
  571.             whandle[count_whandle]=FindFirstChangeNotification(path,FALSE,FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME);
  572.             if (whandle[count_whandle] != INVALID_HANDLE_VALUE) {
  573.               pos_whandle[count_whandle]=pos;
  574.               count_whandle++;
  575.             }
  576.           }
  577.         }
  578.       }
  579.     }
  580.     pos=it.GetNextVisibleItem(pos);
  581.   }
  582.  
  583. }
  584.  
  585. void CDirTreeView::DoTrackHandles() 
  586. {
  587.   CTreeCtrl& tree=GetTreeCtrl();
  588.   if (!tree) return;   /* error */
  589.  
  590.   if (count_whandle) {
  591.     int r=(WaitForMultipleObjects(count_whandle,whandle,FALSE,0)-WAIT_OBJECT_0);
  592.     if ( (r>=0) && (r<count_whandle) ) {      // un item a changΘ
  593.       DestroyTrackHandles();
  594.       HTREEITEM pos=pos_whandle[r];
  595.       RefreshPos(pos);
  596.       tree.SetItemState(pos,TVIS_BOLD,TVIS_BOLD);
  597.       BuildTrackHandles();      /* probleme: on va en rater certains.. */ 
  598.       //FindNextChangeNotification(whandle[r]);
  599.     }
  600.     /*
  601.     int i;
  602.     for(i=0;i<count_whandle;i++)
  603.       FindNextChangeNotification(whandle[i]);
  604.     */
  605.   }
  606. }
  607.  
  608. void CDirTreeView::OnTimer(UINT nIDEvent) 
  609. {
  610.   DoTrackHandles();
  611.   CTreeView::OnTimer(nIDEvent);
  612. }
  613.  
  614. void CDirTreeView::OnShowWindow(BOOL bShow, UINT nStatus) 
  615. {
  616.   static BOOL detach_flag=FALSE;
  617.   if (detach_flag == bShow) return;
  618.   detach_flag=bShow;
  619.  
  620.   if (bShow) {
  621.     HIMAGELIST hSystemImageList;
  622.     SHFILEINFO SHFileInfo;
  623.     hSystemImageList = (HIMAGELIST)SHGetFileInfo("", 0, &SHFileInfo, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
  624.     if (!hSystemImageList) {
  625.       MessageBox("Error: SHGetFileInfo");
  626.       //return;
  627.     } else {
  628.       imagelist.Attach(hSystemImageList);
  629.     }
  630.   } else {
  631.     if (imagelist.m_hImageList) {
  632.       imagelist.Detach();
  633.       imagelist.m_hImageList=NULL;
  634.     }
  635.   }
  636.   //
  637.   CTreeView::OnShowWindow(bShow, nStatus);
  638.   if (bShow)
  639.     StartTimer();
  640.   else
  641.     StopTimer();
  642. }
  643.  
  644.  
  645. void CDirTreeView::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
  646. {
  647.     TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
  648.     // TODO: Add your control notification handler code here
  649.  
  650.   if (pTVDispInfo->item.mask & TVIF_TEXT) {
  651.     if (pTVDispInfo->item.pszText) {
  652.       if (strlen(pTVDispInfo->item.pszText)) {
  653.         CString path=GetItemPath(pTVDispInfo->item.hItem);
  654.         if (path.Right(1)=="\\")
  655.           path=path.Left(path.GetLength()-1);
  656.         CString newpath=path.Left(path.ReverseFind('\\')+1)+pTVDispInfo->item.pszText;
  657.         if (path != newpath) {
  658.           if (!MoveFile(path,newpath)) {
  659.             AfxMessageBox("Unable to rename "+path+" to "+newpath+"!");
  660.           } else {
  661.             GetTreeCtrl().SetItemText(pTVDispInfo->item.hItem,pTVDispInfo->item.pszText);
  662.           }
  663.         }
  664.       }
  665.     }
  666.   }
  667.   
  668.  
  669.     *pResult = 0;
  670. }
  671.  
  672. void CDirTreeView::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult) 
  673. {
  674.     TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
  675.   HTREEITEM selected=GetTreeCtrl().GetSelectedItem();
  676.     *pResult = 0;
  677.     
  678.   int key=pTVKeyDown->wVKey ;
  679.   switch(key) {
  680.   case 32:
  681.     if (selected) {
  682.       GetTreeCtrl().Expand(selected,TVE_TOGGLE);
  683.          *pResult = -1;
  684.     }
  685.     break;
  686.   case 13: case 10:
  687.     if (selected) {
  688.       GetTreeCtrl().Expand(selected,TVE_TOGGLE);
  689.          *pResult = -1;
  690.     }
  691.     break;
  692.   /*default:
  693.     printf("\a");
  694.     break;
  695.   */
  696.   }
  697.  
  698. }
  699.  
  700.  
  701.  
  702. /*
  703. IMPLEMENT_DYNAMIC(CDirTreeViewShellEx, CWinThread)
  704.  
  705. /////////////////////////////////////////////////////////////////////////////
  706. // CDirTreeViewShellEx
  707. BOOL CDirTreeViewShellEx::InitInstance() {
  708.   if (!ShellExecute(NULL,NULL,File,NULL,NULL,SW_SHOWNORMAL)) {
  709.   }
  710.   return 0;
  711. }
  712. */
  713. UINT CDirTreeViewShellEx( LPVOID pP ) {
  714.   CWaitCursor wait;
  715.   CString* File=(CString*) pP;
  716.   if (!ShellExecute(NULL,"open",*File,NULL,NULL,SW_SHOWNORMAL)) {
  717.   }
  718.   delete File;
  719.   return 0;
  720. }
  721.  
  722. UINT CDirTreeViewRefresh( LPVOID pP ) {
  723.   CDirTreeView* _this=(CDirTreeView*) pP;
  724.   if (!_this->redraw_in_progress) {
  725.     _this->redraw_in_progress=1;
  726.     _this->EnsureVisibleBl(_this->refreshPath);
  727.     _this->redraw_in_progress=0;
  728.   }
  729.   return 0;
  730. }
  731.  
  732.  
  733.  
  734. void CDirTreeView::OnKillFocus(CWnd* pNewWnd) 
  735. {
  736.     CTreeView::OnKillFocus(pNewWnd);
  737.     
  738.     CWnd* top_window=this;
  739.     while(top_window->GetParent())
  740.       top_window=top_window->GetParent();
  741.     ((CMainFrame*)top_window)->m_wndStatusBar.SetWindowText("");
  742.     
  743. }
  744.  
  745.